import Fly from 'flyio/dist/npm/wx'
import toast from '@/utils/toast.js'
const fly = new Fly()

// 设置基地址
fly.config.baseURL = 'https://consult-api.itheima.net'

// 设置请求拦截器
fly.interceptors.request.use((request)=>{
  return request
})

// 设置响应拦截器
fly.interceptors.response.use(
  response => {
    if(response.data.code === 500) {
      toast(response.data.message.split('，')[0], 'none')
      return Promise.resolve([response])
    }
    return [null, response.data]
  },
  error => {
    toast.err('网路错误')
    return Promise.resolve([error])
  }
)

export default fly